<div class="form-field">
<#if form.mode == "view">
    <div class="viewmode-field">
        <#if field.mandatory && !(field.value?is_number) && field.value == "">
        <span class="incomplete-warning"><img src="${url.context}/res/components/form/images/warning-16.png" title="${msg("form.field.incomplete")}" /><span>
        </#if>
        <span class="viewmode-label">${field.label?html}:</span>
        <#if field.control.params.activateLinks?? && field.control.params.activateLinks == "true">
            <#assign fieldValue=field.value?html?replace("((http|ftp|https):\\/\\/[\\w\\-_]+(\\.[\\w\\-_]+)+([\\w\\-\\.,@?\\^=%&:\\/~\\+#]*[\\w\\-\\@?\\^=%&\\/~\\+#])?)", "<a href=\"$1\" target=\"_blank\">$1</a>", "r")>
        <#else>
            <#if field.value?is_number>
                <#assign fieldValue=field.value?c>
            <#else>
                <#assign fieldValue=field.value?html>
            </#if>
        </#if>
        <span class="viewmode-value"><#if fieldValue == "">${msg("form.control.novalue")}<#else>${fieldValue}</#if></span>
    </div>
<#else>
    <label for="${fieldHtmlId}">${field.label?html}:<#if field.mandatory><span class="mandatory-indicator">${msg("form.required.fields.marker")}</span></#if></label>
    <input id="${fieldHtmlId}" name="${field.name}" tabindex="0"
           <#if field.control.params.password??>type="password"<#else>type="text"</#if>
           <#if field.control.params.styleClass??>class="${field.control.params.styleClass}"</#if>
           <#if field.control.params.style??>style="${field.control.params.style}"</#if>
           <#if field.value?is_number>value="${field.value?c}"<#else>value="${field.value?html}"</#if>
           <#if field.description??>title="${field.description}"</#if>
           <#if field.control.params.maxLength??>maxlength="${field.control.params.maxLength}"</#if>
           <#if field.control.params.size??>size="${field.control.params.size}"</#if>
           <#if field.disabled && !(field.control.params.forceEditable?? && field.control.params.forceEditable == "true")>disabled="true"</#if> />
    <#if field.control.params.helptext??><div class="help-text" id="${fieldHtmlId}-help" style="display: block;<#if field.control.params.style??>${field.control.params.style};<#else></#if>">${field.control.params.helptext}</div><#else></#if>
</#if>
</div>

<script type="text/javascript">//<![CDATA[
$( document ).ready(function() {
    var updateFields = function(res) {
        var divisionHtmlId = "prop_rccwf_personDivision";
        var positionHtmlId = "prop_rccwf_personPosition";
        var fullNameHtmlId = "prop_rccwf_personFullName";

        var result = eval('(' + res.serverResponse.responseText + ')');
        if (result.userInfo.length > 0) {
            $("input[name="+divisionHtmlId+"]").val(result.userInfo[0].organization);
            $("input[name="+positionHtmlId+"]").val(result.userInfo[0].jobTitle);
            var str = result.userInfo[0].firstName + " " + result.userInfo[0].lastName;
            $("input[name="+fullNameHtmlId+"]").val(str);
        } else {
            Alfresco.util.PopupManager.displayMessage({
                displayTime: 3,
                effectDuration: 1,
                text: 'Klaida gaunant informaciją apie naudotoją.'
            });
        }
    };

    Alfresco.util.Ajax.jsonGet({
        url : Alfresco.constants.PROXY_URI + "user/info/person/"+ (new Date().getTime()),
        successCallback : {
            fn : updateFields,
            scope : this
        },
        failureCallback : {
            fn : function() {
                Alfresco.util.PopupManager.displayMessage({
                    displayTime: 3,
                    effectDuration: 1,
                    text: 'Klaida gaunant informaciją apie naudotoją.'
                });
            },
            scope : this
        }
    });
});
//]]>
</script>
